<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript" src="<%=basePath%>js/initPage.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- Meta, title, CSS, favicons, etc. -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>随便打TCS系统</title>
<!-- Bootstrap -->
<link href="<%=basePath%>vendors/bootstrap/dist/css/bootstrap.min.css"
	rel="stylesheet">
<!-- Font Awesome -->
<link
	href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"
	rel="stylesheet">
<!-- NProgress -->
<link href="<%=basePath%>vendors/nprogress/nprogress.css"
	rel="stylesheet">
<!-- iCheck -->
<link href="<%=basePath%>vendors/iCheck/skins/flat/green.css"
	rel="stylesheet">
<!-- bootstrap-progressbar -->
<link
	href="<%=basePath%>vendors/bootstrap-progressbar/css/bootstrap-progressbar-3.3.4.min.css"
	rel="stylesheet">
<!-- JQVMap -->
<link href="<%=basePath%>vendors/jqvmap/dist/jqvmap.min.css"
	rel="stylesheet" />
<!-- bootstrap-daterangepicker -->
<link
	href="<%=basePath%>vendors/bootstrap-daterangepicker/daterangepicker.css"
	rel="stylesheet">
<!-- Custom Theme Style -->
<link href="<%=basePath%>build/css/custom.min.css" rel="stylesheet">
</head>
<%@ include file="loginCheck.jsp"%>
<body class="nav-md">
	<div class="container body">
		<div class="main_container">
			<div class="col-md-3 left_col">
				<div class="left_col scroll-view">
					<div class="clearfix"></div>
					<br />
				</div>
			</div>
			<!-- page content -->
			<div class="right_col" role="main">
				<div class="">
					<div class="page-title">
						<div class="title_left"></div>
						<div class="x_content">
							<button data-toggle="dropdown"
								class="btn btn-default dropdown-toggle" type="button"
								aria-expanded="false">
								<c:if test="${status==null}"> 全部 </c:if>
								<c:if test="${status==1}"> 成功 </c:if>
								<c:if test="${status==2}"> 未成功 </c:if>
								<span class="caret"></span>
							</button>
							<ul role="menu" class="dropdown-menu">
								<li><a href="javascript:" type="submit"
									<c:if test="${status==null}"> style="display:none;"</c:if>
                                       onclick="selectALL('','1')">全部</a></li>
								<li><a href="javascript:" type="submit"
									<c:if test="${status==1}"> style="display:none;"</c:if>
                                       onclick="selectALL('1','1')">成功</a></li>
								<li><a href="javascript:" type="submit"
									<c:if test="${status==2}"> style="display:none;"</c:if>
                                       onclick="selectALL('2','1')">未成功</a></li>
							</ul>
							所属代理商: <input type="text" id="pname" value="${pname}" /> 
							用户手机号码: <input type="text" id="submobile" value="${submobile}" /> 
							联系电话: <input type="text" id="mobile" value="${mobile}" /> 
							提现时间: <input type="text" id="createtime" value="${createtime}" />
							<button type="submit" class="btn btn-default"
								onclick="selectALL('${status}','1')">搜索</button>
						</div>
					</div>
					<div class="x_panel">
						<div class="x_content">
							<table id="datatable" class="table table-striped table-bordered">
								<thead>
									<tr>
										<th>姓名</th>
										<th>用户手机号码</th>
										<th>所属代理商</th>
										<th>提现类型</th>
										<th>充值账号</th>
										<th>提现金额</th>
										<th>提现时间</th>
										<th>联系电话</th>
										<th>提现类型</th>
										<th>提现状态</th>
										<th>操作</th>
									</tr>
								</thead>
								<tbody>
									<c:forEach items="${upyList}" var="s" varStatus="z">
										<tr>
											<td><c:if test="${s.withdrawals.withdrawalstype == 1 }">
												${s.name}
											</c:if> <c:if test="${s.withdrawals.withdrawalstype == 2 }">
												${s.bankrealname}
											</c:if></td>
											<td>${s.submobile }</td>
											<td>${s.pname }</td>
											<td><c:if test="${s.withdrawals.withdrawalstype == 1 }">
													支付宝
												</c:if> <c:if test="${s.withdrawals.withdrawalstype == 2 }">
													银行卡
												</c:if> <c:if test="${s.withdrawals.withdrawalstype == 3 }">
													话费
												</c:if></td>
											<td><c:if test="${s.withdrawals.withdrawalstype == 1 }">
													${s.aliaccount }
												</c:if> <c:if test="${s.withdrawals.withdrawalstype == 2 }">
													${s.bankno }
												</c:if> <c:if test="${s.withdrawals.withdrawalstype == 3 }">
													${s.mobile }
												</c:if></td>
											<td>${s.withdrawals.money}</td>
											<td><fmt:formatDate value="${s.withdrawals.createtime}"
													type="date" pattern="yyyy-MM-dd" /></td>
											<td>${s.mobile}</td>
											<td><c:if test="${s.withdrawals.type == 1 }">购物订单提现</c:if>
												<c:if test="${s.withdrawals.type == 2 }">充值分润提现</c:if>
												<c:if test="${s.withdrawals.type == 3 }">特权提成提现</c:if>
												<c:if test="${s.withdrawals.type == 4 }">大王卡提成提现</c:if></td>
											<td><c:if test="${s.withdrawals.status == 1 }">已完成提现</c:if>
												<c:if test="${s.withdrawals.status == 2 }">未完成提现</c:if></td>
											<td><c:if test="${s.withdrawals.status == 2 }">
												<%--<c:if test="${s.pid != 'b82d635e95be4bd983acef092118785b'}">--%>
													<button type="button" class="btn btn-success"
															class="form-control"
															onclick="upStatus('${s.withdrawals.id}','1')">完成提现</button>
												<%--</c:if>--%>
												<%--<c:if test="${s.pid == 'b82d635e95be4bd983acef092118785b'}">--%>
													<%--<button type="button" class="btn btn-success"--%>
															<%--class="form-control"--%>
															<%--onclick="upStatus('${s.userid}','${s.pid}','${s.withdrawals.id}','${s.withdrawals.withdrawalstype}')">完成提现</button>--%>
												<%--</c:if>--%>
											</c:if> <c:if test="${s.withdrawals.status == 1 }">
												<button type="submit" class="btn btn-default"
														onclick="upStatus('${s.withdrawals.id}','2')">撤销提现</button>
											</c:if>
												<button type="submit" class="btn btn-danger"
														onclick="upDataStatus('${s.withdrawals.id}','0')">删除</button></td>
											<%--<td><c:if test="${s.withdrawals.status == 2 }">--%>
													<%--<button type="button" class="btn btn-success"--%>
														<%--class="form-control"--%>
														<%--onclick="upStatus('${s.withdrawals.id}','1')">完成提现</button>--%>
												<%--</c:if> <c:if test="${s.withdrawals.status == 1 }">--%>
													<%--<button type="submit" class="btn btn-default"--%>
														<%--onclick="upStatus('${s.withdrawals.id}','2')">撤销提现</button>--%>
												<%--</c:if>--%>
												<%--<button type="submit" class="btn btn-danger"--%>
													<%--onclick="upDataStatus('${s.withdrawals.id}','0')">删除</button></td>--%>
										</tr>
									</c:forEach>
								</tbody>
							</table>
						</div>
					</div>
					<div class="clearfix"></div>
					<br />
				</div>
				<div style="width: 100%; text-align: center;">
					<div id='page'></div>
				</div>
			</div>
		</div>
	</div>
	<!-- jQuery -->
	<script src="<%=basePath%>vendors/jquery/dist/jquery.min.js"></script>
	<script>
		/**
		 * 纯粹的JS分页插件，代码缺点：JS操作DOM冗余太多，太繁琐
		 */ 
		pageUtil.initPage('page', {
			totalCount : '${pages.recordTotal}', //总页数，一般从回调函数中获取。如果没有数据则默认为1页
			curPage : ${pages.currentPageNo}, //初始化时的默认选中页，默认第一页。如果所填范围溢出或者非数字或者数字字符串，则默认第一页
			showCount : 9, //分页栏显示的数量
			pageSizeList : [ 10 ], //自定义分页数，默认[5,10,15,20,50]
			defaultPageSize : 10, //默认选中的分页数,默认选中第一个。如果未匹配到数组或者默认数组中，则也为第一个
			isJump : true, //是否包含跳转功能，默认false
			isPageNum : true, //是否显示分页下拉选择，默认false
			isPN : true, //是否显示上一页和下一面，默认true
			isFL : true, //是否显示首页和末页，默认true
			jump : function(curPage) { //跳转功能回调，传递回来2个参数，当前页和每页大小。如果没有设置分页下拉，则第二个参数永远为0。这里的this被指定为一个空对象，如果回调中需用到this请自行使用bind方法
				selectALL('${status}', curPage);
			},
		});			
	</script>
	<script type="text/javascript">
		var orderNo = "";
		// 主页
		function selectALL(status, curPage) {
			var submobile = $("#submobile").val();
			var mobile = $("#mobile").val();
	        var partten = /^(((13[0-9]{1})|(14[579]{1})|(15[^4,\D]{1})|(16[6]{1})|(18[0-9]{1})|(17[^249,\D]{1})|(19[89]{1}))+\d{8})$/;
	        if (mobile.length != 0 && !partten.test(mobile) || submobile.length != 0 && !partten.test(submobile)) {
	     	 	alert('请输入正确的手机号码');
	         	return false;
	       	}
	        var createtime = $("#createtime").val();
	        var regTime = /^([0-2][0-9][0-9][0-9])-([0-1][0-9])-([0-3][0-9])$/;
	        if (createtime.length != 0 && !regTime.test(createtime)) {
	        	alert('请输入正确日期格式（例如：2018-01-01）');
	         	return false;
	       	}
	        // 判断该代理商是否存在
	        var pname = $("#pname").val();
	        $.ajax({
				type : 'POST',
				url : 'beanName',
				data : {
					username : pname
				},
				success : function(date) {
					if (date == 1){
						alert("该代理商不存在，请检查输入的代理商名称是否正确");
					} else { // 转发
						location.href = "withdrawIndex?status="+status+"&currentPageNo="+curPage+"&mobile="+mobile+"&createtime="
								+createtime+"&submobile="+submobile+"&pname="+pname+"";
					}
				}
			});
		}
		
		// 修改状态
		function upBankCard(id, status, withdrawalsId, withdrawalsType) {
			if(withdrawalsType == 1){
				paymentZFB(id, status, withdrawalsId);
			}
			if(withdrawalsType == 2){
				paymentCard(id, status, withdrawalsId);
			}
		}

		function upStatus(id, status) {
			ajaxPost(id, status, null);
		}
		
		// 删除
		function upDataStatus(id, datastatus) {
			if(!confirm("确认要删除吗，此操作不可撤销")){
				return false;
			}
			ajaxPost(id, null, datastatus);
		}

		// 提现支付宝
		function paymentZFB(userId, parentId, withdrawalsId) {
			$.ajax({
				type : 'POST',
				url : '<%=basePath%>aliPayment/paymentWeb',
				data : {
					userId : userId,
					parentId : parentId,
					withdrawalsId : withdrawalsId
				},
				success : function(date) {
					switch(date.json){
						case -1:
							alert("登录超时，请重新登录");
							top.location.href = "login/${titleId}";
							break;
						case 1:
							alert(date.data);
							location.href = "withdrawIndex?status=${status}&currentPageNo=${pages.currentPageNo}&mobile=${mobile}&createtime=${createtime}"
									+"&submobile=${submobile}&pname=${pname}";
							break;
						default:
							if (date.data != null && date.data != ""){
								alert(date.data);
							} else{
								alert("操作失败，请重新操作");
							}
							break;
					}
				}
			});

		}
		// 提现银行卡
		function paymentCard(userId, parentId, withdrawalsId) {
			$.ajax({
				type : 'POST',
				url : '<%=basePath%>lianlian/paymentWeb',
				data : {
					userId : userId,
					parentId : parentId,
					withdrawalsId : withdrawalsId
				},
				success : function(date) {
					switch(date.json){
						case -1:
							alert("登录超时，请重新登录");
							top.location.href = "login/${titleId}";
							break;
						case 1:
							alert(date.data);
							location.href = "withdrawIndex?status=${status}&currentPageNo=${pages.currentPageNo}&mobile=${mobile}&createtime=${createtime}"
									+"&submobile=${submobile}&pname=${pname}";
							break;
						default:
							if (date.data != null && date.data != ""){
								alert(date.data);
							} else{
								alert("操作失败，请重新操作");
							}
							break;
					}
				}
			});

		}

		// ajaxPost请求
		function ajaxPost(id, status, datastatus) {
			var json = {};        //将数据组成JSON串
			json.id = id;
			json.status = status;
			json.datastatus = datastatus;

			$.ajax({
				type : 'POST',
				url : 'toupdateWithdraw',
				data : JSON.stringify(json),
                contentType : 'application/json',
				success : function(date) {
					switch(date){
				    case -1:
				    	alert("登录超时，请重新登录");
						top.location.href = "login/${titleId}";
				    	break;
				    case 1:
				    	alert("操作成功");
						location.href = "withdrawIndex?status=${status}&currentPageNo=${pages.currentPageNo}&mobile=${mobile}&createtime=${createtime}"
							+"&submobile=${submobile}&pname=${pname}";
						break;
				    default:
				    	alert("操作失败，请重新操作");
				        break;
				    }
				}
			});
		}
	</script>
	<!-- Bootstrap -->
	<script src="<%=basePath%>vendors/bootstrap/dist/js/bootstrap.min.js"></script>
	<!-- FastClick -->
	<script src="<%=basePath%>vendors/fastclick/lib/fastclick.js"></script>
	<!-- NProgress -->
	<script src="<%=basePath%>vendors/nprogress/nprogress.js"></script>
	<!-- bootstrap-daterangepicker -->
	<script src="<%=basePath%>vendors/moment/min/moment.min.js"></script>
	<script
		src="<%=basePath%>vendors/bootstrap-daterangepicker/daterangepicker.js"></script>
	<!-- Chart.js -->
	<script src="<%=basePath%>vendors/Chart.js/dist/Chart.min.js"></script>
	<!-- Custom Theme Scripts -->
	<script src="<%=basePath%>build/js/custom.min.js"></script>
	<!-- layui -->
	<script src="<%=basePath%>vendors/layui/layui.js"></script>

</body>
</html>